package at.jku.ssw.fortress.ui;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.logging.Handler;
import java.util.logging.Logger;

import xtc.parser.Result;
import xtc.parser.SemanticValue;

import com.sun.fortress.nodes.Node;
import com.sun.fortress.parser.Fortress;

public class ParserDriver {
	
	public static Node getAST(String code, String fileName) {
		try {
			Reader in = new StringReader(code);
			Fortress p = new Fortress(in, fileName);
			p.pFile(0);
			Result r = p.pFile(0);
			if (r.hasValue()) {
				SemanticValue v = (SemanticValue) r;
				return (Node) v.value;
			} else {
				System.err.println(r.parseError().msg);
			}
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return null;
	}

}
